/**
 * 
 */
package com.apttbc.looneytuner;

/**
 * @author Alex
 *
 */
public class Notes {
	public static final double[] FREQUENCIES = { 	27.5, 29.1352, 30.8677, 32.7032, 34.6478, 36.7081, 38.8909, 41.2034, 43.6535, 46.2493, 48.9994, 51.9131,
													55.0000, 58.2705, 61.7354, 65.4064, 69.2957, 73.4162, 77.7817, 82.4069, 87.3071, 92.4986, 97.9989, 103.826,
													110.0, 116.541, 123.471, 130.813, 138.591, 146.832, 155.563, 164.814, 174.614, 184.997, 195.998, 207.652,
													220.000, 233.082, 246.942, 261.626, 277.183, 293.665, 311.127, 329.628, 349.228, 369.994, 391.995, 415.305,
													440.0, 466.164, 493.883, 523.251, 554.365, 587.330, 622.254, 659.255, 698.456, 739.989, 783.991, 830.609,
													880.000, 932.328, 987.767, 1046.50, 1108.73, 1174.66, 1244.51, 1244.51, 1396.91, 1479.98, 1567.98, 1661.22,
													1760.00, 1864.66, 1975.53, 2093.00, 2217.46, 2349.32, 2489.02, 2637.02, 2793.83, 2959.96, 3135.96, 3322.44,
													3520.00, 3729.31, 3951.07, 4186.01	};
    public static final String[] NOTES       = {  	"A sub-contra-octave",  "low low A#/Bb",   "low low B",   "C contra-octave"  , "low C#/Db" ,  "low D",   "low D#/Eb",    "low E",   "low F",   "low F#/Gb",     "low G",   "low G#/Ab",
    												"low A",  "low A#/Bb",   "low B",   "C great octave"  , "C#/Db" ,  "D",   "D#/Eb",    "E",   "F",   "F#/Gb",     "G",   "G#/Ab",
    												"A",  "A#/Bb",   "B",   "C small octave"  , "C#/Db" ,  "D",   "D#/Eb",    "E",   "F",   "F#/Gb",     "G",   "G#/Ab",
    												"A",  "A#/Bb",   "B",   "C 1-line octave"  , "C#/Db" ,  "D",   "D#/Eb",    "E",   "F",   "F#/Gb",     "G",   "G#/Ab",
    												"A",  "A#/Bb",   "B",   "C 2-line octave"  , "C#/Db" ,  "D",   "D#/Eb",    "E",   "F",   "F#/Gb",     "G",   "G#/Ab",
    												"A",  "A#/Bb",   "B",   "C 3-line octave"  , "C#/Db" ,  "D",   "D#/Eb",    "E",   "F",   "F#/Gb",     "G",   "G#/Ab",
    												"A",  "A#/Bb",   "B",   "C 4-line octave"  , "C#/Db" ,  "D",   "D#/Eb",    "E",   "F",   "F#/Gb",     "G",   "G#/Ab",
    												"A",  "A#/Bb",   "B",   "C 5-line octave"	};

    //public static final double[] FREQUENCIES2 = { 55.0000, 58.2705, 61.7354, 65.4064, 69.2957, 73.4162, 77.7817, 82.4069, 87.3071, 92.4986, 97.9989, 103.826};
  //  public static final String[] NOTES2       = {  "A͵",  "A♯͵/B♭͵",   "B͵",   "C great octave"  , "C♯/D♭" ,  "D",   "D♯/E♭",    "E",   "F",   "F♯/G♭",     "G",   "G♯/A♭"};

   // public static final double[] FREQUENCIES3 = { 110.0, 116.541, 123.471, 130.813, 138.591, 146.832, 155.563, 164.814, 174.614, 184.997, 195.998, 207.652};
   // public static final String[] NOTES3       = {  "A",  "A♯͵/B♭͵",   "B͵",   "c small octave"  , "c♯/d♭" ,  "d",   "d♯/e♭",    "e",   "f",   "f♯/g♭",     "g",   "g♯/a♭"};
 
    //public static final double[] FREQUENCIES4 = { 220.000, 233.082, 246.942, 261.626, 277.183, 293.665, 311.127, 329.628, 349.228, 369.994, 391.995, 415.305};
  // public static final String[] NOTES4       = {  "a",  "a♯/b♭",   "b",   "c′ 1-line octave"  , "c♯′/d♭′" ,  "d′",   "d♯′/e♭′",    "e′",   "f′",   "f♯′/g♭′",     "g′",   "g♯′/a♭′"};
  
   // public static final double[] FREQUENCIES5 = { 440.0, 466.164, 493.883, 523.251, 554.365, 587.330, 622.254, 659.255, 698.456, 739.989, 783.991, 830.609};
  //  public static final String[] NOTES5       = {  "a′",  "a♯′/b♭′",   "b′",   "c′′ 2-line octave"  , "c♯′′/d♭′′" ,  "d′′",   "d♯′′/e♭′′",    "e′′",   "f′′",   "f♯′′/g♭′′",     "g′′",   "g♯′′/a♭′′"};
  
    //public static final double[] FREQUENCIES6 = { 880.000, 932.328, 987.767, 1046.50, 1108.73, 1174.66, 1244.51, 1244.51, 1396.91, 1479.98, 1567.98, 1661.22};
  //  public static final String[] NOTES6       = {  "a′′",  "a♯′′/b♭′′",   "b′′",   "c′′′ 3-line octave"  , "c♯′′′/d♭′′′" ,  "d′′′",   "d♯′′′/e♭′′′",    "e′′′",   "f′′′",   "f♯′′′/g♭′′′",     "g′′′",   "g♯′′′/a♭′′′"};
  
   // public static final double[] FREQUENCIES7 = { 1760.00, 1864.66, 1975.53, 2093.00, 2217.46, 2349.32, 2489.02, 2637.02, 2793.83, 2959.96, 3135.96, 3322.44};
  //  public static final String[] NOTES7       = {  "a′′′",  "a♯′′′/b♭′′′",   "b′′′",   "c′′′′ 4-line octave"  , "c♯′′′′/d♭′′′′" ,  "d′′′′",   "d♯′′′′/e♭′′′′",    "e′′′′",   "f′′′′",   "f♯′′′′/g♭′′′′",     "g′′′′",   "g♯′′′′/a♭′′′′"};
  
  //  public static final double[] FREQUENCIES8 = { 3520.00, 3729.31, 3951.07, 4186.01};
 //   public static final String[] NOTES8       = {  "a′′′′",  "a♯′′′′/b♭′′′′",   "b′′′′",   "c′′′′′ 5-line octave"};
  
    
    public static int getNote(double freq){
    	double smallestDiff = Math.abs(freq - FREQUENCIES[0]);
    	int closestIndex = 0;
    	for(int i = 0; i < FREQUENCIES.length; i++){
    		double difference = Math.abs(freq - FREQUENCIES[i]);
    		if(difference < smallestDiff){
    			closestIndex = i;
    			smallestDiff = difference;
    		}
    	}
    	return closestIndex;
    }
    
    public static String getNoteString(int i) {
    	return NOTES[i];
    }
    
    public static double getDifference(int noteIndex, double freq){
    	return freq - FREQUENCIES[noteIndex];
    }
    
    
    public static double getCents(int noteIndex, double freq) {
    	return (1200*3.322038403*Math.log10(freq/FREQUENCIES[noteIndex]));
    }
    
}
